<?php

function smarty_function_getbrand_by_topic_id($params, &$smarty) {
    //Get value from page
    $id = $params['topic_id'];
    if($id){
      //Query data

    $pntables = pnDBGetTables();
    $tpc_table  = $pntables['innoforum_topics'];
    $tpc_column = $pntables['innoforum_topics_column'];
		
		$brand_table = $pntables['innoforum_brand'];
		$brand_column = $pntables['innoforum_brand_column'];

      $sql = "SELECT
                $brand_table.$brand_column[id] as brand_id,
                $brand_table.$brand_column[name] as brand_name
              FROM 
                $tpc_table ,
                $brand_table
              WHERE
                $tpc_table.$tpc_column[id] = $id
              AND
                $brand_table.$brand_column[id] = $tpc_table.$tpc_column[brand_id] 
							AND 
								$tpc_table.$tpc_column[brand_id] != 99999								
							";

      $column = array("brand_id","brand_name");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);
			if(isset($objectArray)){
				$smarty->assign("brand_id", $objectArray['0']['brand_id']);
				$smarty->assign("brand_name", $objectArray['0']['brand_name']);
			}else{
				$smarty->assign("brand_id", NULL);
				$smarty->assign("brand_name", NULL);
			}



    }


}